<!--#include file=..\checkSession.inc-->
<!--#include file="..\RootContent.inc"-->
<!--#include file=..\getFormName.inc-->
<script language=vbscript runat=server>
	Function ChangeYear(bNewyear,bOldyear,bPth,bPthOld)		
		if bPthOld<>bPth then
			Set F= Server.CreateObject("ActiveFile.File")
			F.Name=bPthOld		    
			if F.Exists() then
				F.Delete()
			end if
			Set f=nothing
			
		end if
		Set bDir=server.CreateObject("ActiveFile.Directory")
	    bPathFolder=RootContent & "Upload\" &bNewyear
        bDir.Path=bPathFolder
       	if not bDir.Exists() then
	    	call bDir.Create(bPathFolder)
    	end if
	   	bPathFolderDen=bPathFolder & "\Den"
	   	bDir.Path=bPathFolderDen	    	
	  	if not bDir.Exists() then
	   		Call bDir.Create(bPathFolderDen)
	   	end if
	   	bPathFolderText=bPathFolderDen & "\Text"
    	bDir.Path=bPathFolderText
       	if not bDir.Exists() then
	   		Call bDir.Create(bPathFolderText)
	   	end if

		bPathFolderDi=bPathFolder & "\Di"
	   	bDir.Path=bPathFolderDi	
	   	if not bDir.Exists() then
	   		Call bDir.Create(bPathFolderDi)
	   	end if
	   	bPathFolderText=bPathFolderDi & "\Text"
    	bDir.Path=bPathFolderText
       	if not bDir.Exists() then
	   		Call bDir.Create(bPathFolderText)
	   	end if
	   	
		bPathFolderDuthao=bPathFolder & "\Duthao"
	  	bDir.Path=bPathFolderDuthao
	   	if not bDir.Exists() then
	  		Call bDir.Create(bPathFolderDuthao)
	   	end if
	   	bPathFolderText=bPathFolderDuthao & "\Text"
    	bDir.Path=bPathFolderText
       	if not bDir.Exists() then
	   		Call bDir.Create(bPathFolderText)
	   	end if
		bPathFolderNoibo=bPathFolder & "\Noibo"
	   	bDir.Path=bPathFolderNoibo	
	   	if not bDir.Exists() then
	   		Call bDir.Create(bPathFolderNoibo)
	   	end if
	   	bPathFolderText=bPathFolderNoibo & "\Text"
    	bDir.Path=bPathFolderText
       	if not bDir.Exists() then
	   		Call bDir.Create(bPathFolderText)
	   	end if
		bPathFolderQuyetdinh=bPathFolder & "\Quyetdinh"
	   	bDir.Path=bPathFolderQuyetdinh
	   	if not bDir.Exists() then
	   		Call bDir.Create(bPathFolderQuyetdinh)
	   	end if
	   	bPathFolderText=bPathFolderQuyetdinh & "\Text"
    	bDir.Path=bPathFolderText
       	if not bDir.Exists() then
	   		Call bDir.Create(bPathFolderText)
	   	end if	   	
		bPathFolderDenCB=bPathFolder & "\DenCB"
	   	bDir.Path=bPathFolderDenCB
	   	if not bDir.Exists() then
	   		Call bDir.Create(bPathFolderDenCB)
	   	end if
	   	bPathFolderText=bPathFolderDenCB & "\Text"
    	bDir.Path=bPathFolderText
       	if not bDir.Exists() then
	   		Call bDir.Create(bPathFolderText)
	   	end if
   		bPathFolderTotrinh=bPathFolder & "\Totrinh"
	   	bDir.Path=bPathFolderTotrinh
	   	if not bDir.Exists() then
	   		Call bDir.Create(bPathFolderTotrinh)
	   	end if
		Set bDir=nothing
	End function
</script>
<%				
	set TextFile=server.CreateObject("Vinalines.ClsFile")
	bLoaiVT=Request("bLoaiVT")
	bComm=Request("bComm")
	bMa=Request("bMa")
	bNamcu=cstr(Request("bNamcu"))
	bNam=cstr(Request("bNam"))
	if bComm="ghi" then
		Select Case bLoaiVT
			Case "1" 'Den			
				'Save Text
				PathOld=RootContent & "Upload\"& bNamcu &"\Den\Text"
				PathOld=Path & "\" & bMa & ".VT" 
				Path=RootContent & "Upload\"& bNam &"\Den\Text"
				Path=Path & "\" & bMa & ".VT" 
				call ChangeYear(bNam,bNamcu,Path,PathOld)
				TextFile.SaveFile Request("Body"),Path				
				bNamcu=bNam
			Case "2" 'Di
				PathOld=RootContent &  "Upload\"& bNamcu &"\Di\Text"
'Hien 21_05 (replace)
				PathOld=Path & "\" & replace(bMa,"/","_") & ".VT" 
				Path=RootContent & "Upload\"& bNam &"\Di\Text"
				Path=Path & "\" & replace(bMa,"/","_") & ".VT" 
				call ChangeYear(bNam,bNamcu,Path,PathOld)
				TextFile.SaveFile Request("Body"),Path
			Case "3" 'Du thao
				PathOld=RootContent & "Upload\"& bNamcu &"\Duthao\Text"
				PathOld=Path & "\" & bMa & ".VT" 
				Path=RootContent & "Upload\"& bNam &"\Duthao\Text"
				Path=Path & "\" & bMa & ".VT" 
				call ChangeYear(bNam,bNamcu,Path,PathOld)
				TextFile.SaveFile Request("Body"),Path
			Case "4" 'Noibo
				PathOld=RootContent & "Upload\"& bNamcu &"\noibo\Text"
				PathOld=Path & "\" & bMa & ".VT" 
				Path=RootContent & "Upload\"& bNam &"\noibo\Text"
				Path=Path & "\" & bMa & ".VT" 
				call ChangeYear(bNam,bNamcu,Path,PathOld)
				TextFile.SaveFile Request("Body"),Path
'Hien 22_05
			Case "5" 'Quyet dinh
				PathOld=RootContent & "Upload\"& bNamcu &"\Quyetdinh\Text"
				PathOld=Path & "\" & replace(bMa,"/","_") & ".VT" 
				Path=RootContent & "Upload\"& bNam &"\Quyetdinh\Text"
				Path=Path & "\" & replace(bMa,"/","_") & ".VT" 
				call ChangeYear(bNam,bNamcu,Path,PathOld)
				TextFile.SaveFile Request("Body"),Path
			Case "6" 'DenCB
				PathOld=RootContent & "Upload\"& bNamcu &"\DenCB\Text"
				PathOld=Path & "\" & bMa & ".VT" 
				Path=RootContent & "Upload\"& bNam &"\DenCB\Text"
				Path=Path & "\" & bMa & ".VT" 
				call ChangeYear(bNam,bNamcu,Path,PathOld)
				TextFile.SaveFile Request("Body"),Path
		End Select		
	end if	
	if bComm="" then
		Set Rec=server.CreateObject("ADODB.Recordset")
		sSQL="Select * from VTDen where ID Like '"& bMa &"'"
	end if
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft FrontPage 5.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<TITLE></TITLE>
<script language=vbscript runat=server>
	Function ModiString(mess_s)
		message = Replace("" & mess_s,"'", "''")
		ModiString=message
	End function
</script>	
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--

function CmdOK_onclick() {
	frmeditor.Body.value=document.all.dynamsg.html;
	frmeditor.action="frmedit.asp?bComm=ghi&bNamcu="+"<%=bnamcu%>"+"&bNam="+"<%=bnam%>"+"&bMa="+"<%=bMa%>"+"&bLoaiVT="+"<%=bLoaiVT%>";
	frmeditor.submit();
}
function CmdAttach_onclick() {
	frmeditor.Body.value=document.all.dynamsg.html;
	frmeditor.action="Attach.asp?bPost=ok&bNamcu="+"<%=bnamcu%>"+"&bNam="+"<%=bnam%>"+"&Filename="+"<%=bMa%>"+"&bMa="+"<%=bMa%>"+"&bLoaiVT="+"<%=bLoaiVT%>";
	frmeditor.submit();
}

function CmdExit_onclick() {
	<%if bLoaiVT="1" then%>	
		frmeditor.action="../xuly/frmvtden.asp?bComm=edit&bNamcu="+"<%=bnamcu%>"+"&bNam="+"<%=bnam%>"+"&TxtID="+"<%=bMa%>"
	<%end if%>
	<%if bLoaiVT="2" then%>	
		frmeditor.action="../xuly/frmvtdi.asp?bComm=edit&bNamcu="+"<%=bNamcu%>"+"&bNam="+"<%=bnam%>"+"&TxtID="+"<%=bMa%>"
	<%end if%>
	<%if bLoaiVT="3" then%>	
		frmeditor.action="../xuly/frmvtduthao.asp?bComm=edit&bNamcu="+"<%=bnamcu%>"+"&bNam="+"<%=bnam%>"+"&bID="+"<%=bMa%>"
	<%end if%>
	<%if bLoaiVT="4" then%>	
		frmeditor.action="../xuly/frmvtnoibo.asp?bComm=edit&bNamcu="+"<%=bnamcu%>"+"&bNam="+"<%=bnam%>"+"&bID="+"<%=bMa%>"
	<%end if%>
	<%if bLoaiVT="5" then%>	
		frmeditor.action="../xuly/frmvtQuyetdinh.asp?bComm=edit&bNamcu="+"<%=bnamcu%>"+"&bNam="+"<%=bnam%>"+"&TxtID="+"<%=bMa%>"
	<%end if%>
	<%if bLoaiVT="6" then%>	
		frmeditor.action="../xuly/frmvtDenCB.asp?bComm=edit&bNamcu="+"<%=bnamcu%>"+"&bNam="+"<%=bnam%>"+"&TxtID="+"<%=bMa%>"
	<%end if%>
	frmeditor.submit();
}

//-->
</SCRIPT>
</HEAD>
<BODY  bgcolor=#F8F9D9  leftmargin=0 topmargin=0 LANGUAGE=javascript onload="return window_onload()">
<form name=frmeditor method=post>	
	<div style='position:relative;top=0px;left=0px;height:90%' width="100%">
		<%if bComm="" then%>
			<%
				Select Case bLoaiVT
					Case "1"					  
						path=RootContent & "Upload\"& bNam &"\Den\Text\"
						Path=Path & "\" & bMa & ".VT" 
					Case "2"
						path=RootContent & "Upload\"& bNam &"\Di\Text\"
'Hien 21_05
						Path=Path & "\" & replace(bMa,"/","_") & ".VT"
					Case "3"
						path=RootContent & "Upload\"& bNam &"\Duthao\Text\"
						Path=Path & "\" & bMa & ".VT" 
					Case "4"
						path=RootContent & "Upload\"& bNam &"\Noibo\Text\"
						Path=Path & "\" & bMa & ".VT"
'Hien 22_05
					Case "5"
						path=RootContent & "Upload\"& bNam &"\Quyetdinh\Text\"
						Path=Path & "\" & replace(bMa,"/","_") & ".VT"
					Case "6"
						path=RootContent & "Upload\"& bNam &"\DenCB\Text\"
						Path=Path & "\" & bMa & ".VT"
				End Select				
			%>
			<%if request("chuyendi")="ok" then%>
				<textarea name="Body" style='visibility:hidden;position:absolute;top:0px;left:0px' rows="5" cols="20%"><%=Session("bND")%></textarea>
			<%Session("bND")=""%>
			<%else%>
				<textarea name="Body" style='visibility:hidden;position:absolute;top:0px;left:0px' rows="5" cols="20%"><%=TextFile.ReadTextFile(path)%></textarea>						
			<%end if%>
		<%else%>				
			<textarea name="Body" style='visibility:hidden;position:absolute;top:0px;left:0px' rows="5" cols="20%"><%=Request("Body")%></textarea>
		<%end if%>
		<div id="plainmsg" style='visibility:hidden;position:absolute;top:0px;left:0px'></div>
		<object id="dynamsg" width="100%" style="position:absolute;top:0px;left:0px" height="100%" data="deditor.asp" viewastext type="text/x-scriptlet"></object>
	</div>				
	<Table border=0 width="100%" style='position:absolute;top:90%;left:0px'>
		<TR>
			<TD width="50%"><Button name="CmdAttach" style='font-family:Arial;width:110' LANGUAGE=javascript onclick="return CmdAttach_onclick()" accesskey="K"><p>
            Gắn <u>k</u>èm tệp tin</p></Button></TD>
			<TD width="50%" align=right>
				<Button name="CmdOK"  style='font-family:Arial;width:80' LANGUAGE=javascript onclick="return CmdOK_onclick()" accesskey="G"><p><u>G</u>hi nhận</p></Button>
				<Button name="CmdExit" style='font-family:Arial;width:80'  LANGUAGE=javascript onclick="return CmdExit_onclick()" accesskey="T"><p><u>T</u>hoát</p></Button>
			</TD>
		<TR>
	</Table>	
</form>
</BODY>
</HTML>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
	function window_onload() {
		document.all.dynamsg.html=frmeditor.Body.value;
	}
</Script>